home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 2002 #11 / Amiga Plus CD - 2002 - No. 11.iso / Tools / Development / TinyGL / ami / content / ad709 / tinygl / src / oscontext.c < prev    next >
Encoding:
C/C++ Source or Header  |  2002-08-15  |  2.1 KB  |  87 lines

  1. /*$T oscontext.c GC 1.137 08/09/02 17:47:18 */
  2.  
  3. /*$6
  4.  +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  5.  +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  6.  */
  7.  
  8. #include "oscontext.h"
  9. #include "zbuffer.h"
  10. #include "zgl.h"
  11. #include <ad709/tinygl/gl.h>
  12. #include <stdlib.h>
  13. #include <assert.h>
  14.  
  15. static int    buffercnt = 0;
  16.  
  17. /* */
  18.  
  19. ostgl_context *ostgl_create_context(const int xsize, const int ysize, const int depth,
  20.                                     void **framebuffers, const int numbuffers) {
  21.     ostgl_context    *context;
  22.     int                i;
  23.     ZBuffer            *zb;
  24.     /*~~~~~~~~~~~~~~~~~~~~~*/
  25.  
  26.     assert(depth == 16);    /* support for other depths must include bpp convertion */
  27.     assert(numbuffers >= 1);
  28.  
  29.     context = malloc(sizeof(ostgl_context));
  30.     assert(context);
  31.     context->zbs = malloc(sizeof(void *) * numbuffers);
  32.     context->framebuffers = malloc(sizeof(void *) * numbuffers);
  33.  
  34.     assert(context->zbs != NULL && context->framebuffers != NULL);
  35.  
  36.     for(i = 0; i < numbuffers; i++) {
  37.         context->framebuffers[i] = framebuffers[i];
  38.         zb = ZB_open(xsize, ysize, ZB_MODE_5R6G5B, 0, NULL, NULL, framebuffers[i]);
  39.         if(zb == NULL) {
  40.             fprintf(stderr, "Error while initializing Z buffer\n");
  41.             exit(1);
  42.         }
  43.  
  44.         context->zbs[i] = zb;
  45.     }
  46.  
  47.     if(++buffercnt == 1) {
  48.         glInit(context->zbs[0]);
  49.     }
  50.  
  51.     context->xsize = xsize;
  52.     context->ysize = ysize;
  53.     context->numbuffers = numbuffers;
  54.     return context;
  55. }
  56.  
  57. /* */
  58. void ostgl_delete_context(ostgl_context *context) {
  59.     int i;
  60.     for(i = 0; i < context->numbuffers; i++) {
  61.         ZB_close(context->zbs[i]);
  62.     }
  63.  
  64.     free(context->zbs);
  65.     free(context->framebuffers);
  66.     free(context);
  67.  
  68.     if(--buffercnt == 0) {
  69.         glClose();
  70.     }
  71. }
  72.  
  73. /* */
  74. void ostgl_make_current(ostgl_context *oscontext, const int idx) {
  75.     GLContext    *context = gl_get_context();
  76.     assert(idx < oscontext->numbuffers);
  77.     context->zb = oscontext->zbs[idx];
  78. }
  79.  
  80. /* */
  81. void ostgl_resize(ostgl_context *context, const int xsize, const int ysize, void **framebuffers) {
  82.     int i;
  83.     for(i = 0; i < context->numbuffers; i++) {
  84.         ZB_resize(context->zbs[i], framebuffers[i], xsize, ysize);
  85.     }
  86. }
  87.